package com.ryanm.sage.handlers;

import java.io.IOException;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;

import com.ryanm.sage.Handler;
import com.ryanm.sage.ProcessUtil;
import com.ryanm.sage.SheevaSage;

/**
 * Adds magnet links to transmission
 * 
 * @author ryanm
 */
public class MagnetHandler extends Handler {
	@Override
	public boolean handle( Message m, XMPPConnection connection ) {
		if( m.getBody().toLowerCase().startsWith( "magnet:" ) ) {
			try {
				SheevaSage.reply( m, "Give me a moment here...", connection );
				ProcessUtil.execute( true, null, null, "transmission-remote", "-a",
						m.getBody() );
				SheevaSage.reply( m, "done", connection );
			}
			catch( IOException e ) {
				SheevaSage.reply( m, "Well that didn't go very well.", connection );
			}
			return true;
		}
		return false;
	}
}
